In [ ]:
%matplotlib inline
import pandas as pd
import gnucash_pandas
import numpy as np

def plot_df(df, **kwargs):
    return df.loc[df.index > '2015-01-01'].plot(figsize=(16,8), grid=True, **kwargs)

In [ ]:
gnucash_file = input("Path to GnuCash file to load ")
df = gnucash_pandas.splits_dataframe(gnucash_file)

In [ ]:
expenses = gnucash_pandas.daily(df, 'Expense')
expenses

In [ ]:
monthly_expenses = expenses.rolling(31).sum()
monthly_expenses

Monthly Expenses

This plot displays rolling 32-day expenses by category.


In [ ]:
plt = plot_df(monthly_expenses)
plt.legend(loc='lower center', ncol=4, bbox_to_anchor=(0.5,-0.6))
plt

Total Monthly Expenses


In [ ]:
total_monthly_expenses = monthly_expenses.sum(axis=1) # axis=1 means sum columns
plot_df(total_monthly_expenses)

In [ ]:
income = -gnucash_pandas.daily(df, 'Income')
income

In [ ]:
monthly_income = income.rolling(31).sum()
monthly_income

Monthly Income


In [ ]:
plt = plot_df(monthly_income)
plt.legend(loc='lower center', ncol=4, bbox_to_anchor=(0.5,-0.3))
plt

Total Monthly Income


In [ ]:
total_monthly_income = monthly_income.sum(axis=1) # axis=1 means sum columns
plot_df(total_monthly_income)

Percentage of income spent

This is the proportion of monthly income spent on monthly expenses.


In [ ]:
pct_expenses = total_monthly_expenses/total_monthly_income
plot_df(pct_expenses, ylim=(0,2), yticks=np.linspace(0, 2, num=9))

In [ ]:
taxes = [
    "CA Private Disability Employee",
    "CA State Income Tax",
    "Employee Medicare",
    "Federal Income Tax",
    "Social Security Employee Tax", 
    "Taxes",
]
tax_free_expenses = monthly_expenses.drop(taxes, axis=1)
tax_free_expenses

Monthly after-tax expenses


In [ ]:
plt = plot_df(tax_free_expenses)
plt.legend(loc='lower center', ncol=4, bbox_to_anchor=(0.5,-0.55))
plt

Total after-tax expenses


In [ ]:
total_tax_free_expenses = tax_free_expenses.sum(axis=1) # axis=1 means sum columns
plot_df(total_tax_free_expenses)

Total after-tax income


In [ ]:
total_tax_expenses = total_monthly_expenses - total_tax_free_expenses
total_after_tax_income = total_monthly_income - total_tax_expenses
plot_df(total_after_tax_income)

Percentage of after-tax income spent


In [ ]:
after_tax_pct_expenses = total_tax_free_expenses/total_after_tax_income
plot_df(after_tax_pct_expenses, ylim=(0,2), yticks=np.linspace(0, 2, num=9))

Food Expenses


In [ ]:
food_expenses = monthly_expenses[["Dining", "Groceries"]].copy()
food_expenses["Total"] = food_expenses.sum(axis=1)
plot_df(food_expenses)

In [ ]: